<template>
  <el-card>

    <el-table
        v-loading="data.loading === true"
        :data="data.tableData"
        style="width: 100%; margin-top: 10px; overflow: hidden"
        @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" sortable ></el-table-column>
      <el-table-column prop="id" label="序号" sortable min-width="100"></el-table-column>
      <el-table-column prop="reIp" label="IP地址" sortable min-width="100"></el-table-column>
      <el-table-column prop="reUa" label="User-Agent" sortable min-width="300"></el-table-column>
      <el-table-column prop="accessTime" label="登陆时间" sortable min-width="100"></el-table-column>
    </el-table>
    <div v-if="data.total" style="margin-top: 10px">
      <el-pagination
          background
          small
          :page-size="data.pageSize"
          :current-page="data.pageNum"
          layout="total,prev, pager, next,jumper"
          :total="data.total"
          @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
  </el-card>
</template>



<script setup>

import {onMounted, reactive} from "vue";
import {listLoginLogApi} from "@/api/log";

const data=reactive({
  tableData:[],
  loading:false,
  total:0,
  pageNum:1,
  pageSize:10,
  keyword:'',
})

onMounted(()=>{
  getLoginLogList();

})
const getLoginLogList=()=>{
  data.loading=true;
  setTimeout(() => {
    data.loading = false;
  }, 1000);
  listLoginLogApi({
    pageNum:data.pageNum,
    pageSize:data.pageSize,
    keyword:data.keyword,
  }).then(res=>{
    // console.log(res);
    data.tableData=res.data.list;
    data.total=res.data.total;
    data.pageNum=res.data.pageNum;
    data.pageSize=res.data.pageSize;
  }).catch(err=>{
    console.log(err);
  })
}

const handleSelectionChange=(selection)=>{
  data.selectedIds = selection.map(item => item.id);
}
const handleCurrentChange = (number) => {
  data.pageNum=number;
  getLoginLogList();
}
</script>
<style scoped>

</style>